home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / comm / tcp / AutoADT1_21.lha / AutoADT.rexx < prev   
OS/2 REXX Batch file  |  1995-05-14  |  5KB  |  196 lines

  1. /* AutoADT by Dan J. Fraser
  2.  *
  3.  * Based on Browse.DaFTP by Osma Ahvenlampi and Dan Murrell, Jr.
  4.  *
  5.  * $VER: AutoADT 1.12 (950412)
  6.  */
  7.  
  8.  
  9. /******* user-editable values ******/
  10.  
  11.  
  12. temppath = 'T:'                 /* Where AutoADT will put its temp
  13.                                  * files. */
  14.  
  15. rootpath = 'UDBase0:'           /* The root of yer Aminet tree */
  16.  
  17. badpath =  'UDBase0:NewFiles/'  /* Where unfilable files will go */
  18.  
  19.  /* PATHNAMES ---MUST--- END IN / or : */
  20.  
  21. defhostname = 'ftp.netnet.net'  /* Default Aminet site */
  22.  
  23. logfile = 'LOGS:AutoADT.log'    /* AutoADT's logfile */
  24.  
  25. giveup = 0                      /* Give up after a failed transfer?
  26.                                  * 0 = no, 1 = yes */
  27.  
  28. verbosity = -1                  /* Want to see more of the FTP
  29.                                  * output?  0 = no, 1 = yes. 
  30.                                  * -1 = Show NO FTP output */
  31.                                   
  32. /******* The program's Main Magic ********/
  33.  
  34.  
  35. if ~show(l, 'rexxsupport.library') then
  36.     if ~addlib('rexxsupport.library', 0, -30, 0) then
  37.         exit 50
  38.  
  39.     parse arg hostname
  40.  
  41.  
  42.     say 'AutoADT 1.12 - by Dan Fraser'
  43.  
  44.     if hostname = '' then hostname=defhostname
  45.  
  46.     if ~exists( logfile ) then
  47.         if open( logit, logfile, 'W' ) then do
  48.             call writeln( logit, 'Logfile created on '||date('O')||' at '||time('C') )
  49.             call close ( logit )
  50.         end
  51.  
  52.     if ~exists( "ENVARC:AutoADT" ) then
  53.         if open( fsitelist, "ENVARC:AutoADT", 'W' ) then do
  54.             call writeln( fsitelist, '0' )
  55.             call writeln( fsitelist, '' )
  56.             call close( fsitelist )
  57.         end
  58.  
  59.  
  60.     if open( fdate, "ENVARC:AutoADT", 'R' ) then do
  61.         lastdate = readln( fdate )
  62.         temp = readln( fdate )
  63.         call close( fdate )
  64.     end
  65.     else do
  66.         lastdate = 0
  67.         findsite = ""
  68.         use_gzip = 0
  69.         maxfind = 30
  70.     end
  71.  
  72.     redir = verbosity    
  73.  
  74.     lg='**** AutoADT started successfully.';call dolog
  75.  
  76.     pragma('D',temppath)
  77.     say 'Getting RECENT file...'
  78.     address command 'ncftp -N -V '||redir hostname||':/pub/aminet/info/adt/ADT_RECENT_7' 
  79.  
  80.     if ~open( frecent , "ADT_RECENT_7" , 'R' ) then do
  81.         lg = 'ERROR - Couldn''t get RECENT file';call dolog 
  82.         say 'Couldn''t get RECENT file!'
  83.         exit 50
  84.     end
  85.  
  86.     say 'Processing RECENT...'
  87.     recentfile=temppath||'ADT_RECENT_7'
  88.  
  89.     line = readln( frecent )
  90.     if line ~= "#adt-v2" then do
  91.         call close( frecent )
  92.         return "Wrong ADT_RECENT version"
  93.     end
  94.  
  95.  
  96.     do while abbrev( line, "#", 1 )
  97.         line = readln( frecent )
  98.     end
  99.  
  100.     newdate = lastdate
  101.     newfiles = 0
  102.     badfiles = 0 
  103.     errors = 0
  104.  
  105.     if list = 1 then
  106.         lastdate = 0
  107.  
  108.     do while line ~= "" & ~abbrev( line, '#' )
  109.         parse var line file.date '@' file.dir '@' file.name '@' file.size '@' a '@' b '@' c '@' file.desc
  110.         if file.date > lastdate then do
  111.             if newdate <= file.date then
  112.                 newdate = file.date
  113.             dot = lastpos(".", file.name)
  114.             if (dot > 0) then
  115.                 file.readme = left(file.name, dot) || 'readme'
  116.             else
  117.                 file.readme = file.name'.readme'
  118.  
  119.         cdbad = 'cd' badpath
  120.         cdlin = 'cd' rootpath||file.dir
  121.         lin = 'ncftp -N -V '||redir hostname':/pub/aminet/'file.dir'/'file.name
  122.  
  123.         quotes = 1
  124.         do while quotes < length(file.desc)+1
  125.             if substr(file.desc,quotes,1)='"' then do
  126.                 file.desc=insert('*',file.desc,quotes-1)
  127.                 quotes=quotes+1
  128.             end
  129.             quotes=quotes+1
  130.         end
  131.  
  132.         notelin = 'filenote' file.name '"'file.desc'"'
  133.         badnote = 'filenote' badpath||file.name '"'file.desc'"'
  134.  
  135.             pragma('D',badpath);
  136.             pragma('D',rootpath||file.dir);
  137.             say ' '
  138.             say 'Getting File to: '||rootpath||file.dir'/'file.name
  139.             address command lin
  140.  
  141.             if ~exists( rootpath||file.dir'/'file.name ) then
  142.                 if ~exists( badpath||file.name ) then do
  143.                     lg = 'ERROR getting file '||file.dir||'/'||file.name;call dolog
  144.                     if giveup then do
  145.                         lg = 'Giving up!';call dolog
  146.                         say 'Big error! I''m crapping out.'
  147.                         exit(50)
  148.                     end
  149.                     errors=1
  150.                 end; else do
  151.                     badfiles=badfiles+1
  152.                     lg = 'ERROR put file '||file.dir||'/'||file.name||' in '||badpath;call dolog
  153.                     address command badnote
  154.                 end
  155.             else do
  156.                 newfiles=newfiles+1
  157.                 lg = 'Got '||file.dir||'/'||file.name||' successfully.';call dolog
  158.  
  159.  
  160.                 say 'Adding filenote: '||file.desc
  161.                 address command notelin
  162.             end 
  163.         end 
  164.  
  165.         line = readln( frecent )
  166.     end
  167.  
  168.     call close( frecent )
  169.     call close( batchout )
  170.  
  171.     lastdate = newdate
  172.  
  173.     lg = 'Transfer completed. '||newfiles||' new files, '||badfiles||' bad.';call dolog
  174.     if errors then do 
  175.         lg = 'Errors occured during the transfer.'
  176.         call dolog    
  177.     end
  178.  
  179.     say 'Updating config file...'
  180.  
  181.     if open( fprefs, "ENVARC:AutoADT", 'W' ) then do
  182.         call writeln( fprefs, lastdate )
  183.     end 
  184.     call close( fprefs )
  185.  
  186.     address command 'delete '||temppath||'ADT_RECENT_7 QUIET'
  187.  
  188.     exit(0)
  189.  
  190. DoLog:
  191.     if open( logit, logfile, 'A'  ) then do
  192.         call writeln( logit, date('O')||' 'time('N')||'  '||lg)
  193.         call close( logit )
  194.     end
  195.  
  196.